package mrh.niubi.librarysystem.controller;

import  mrh.niubi.librarysystem.common.Result;
import mrh.niubi.librarysystem.service.AvatarService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/avatar")
@CrossOrigin(origins = "*")
public class AvatarController {

    @Resource
    private AvatarService avatarService;
    //上传头像
    @PostMapping("/")
    public Result uploadAvatar(@RequestParam MultipartFile file){
        System.out.println("uploadAvatar====>");
        String url = avatarService.upload(file);
        return Result.success(url);
    }
    //根据文件名下载文件，即文件的url
    @GetMapping("/{fileName}")
    public void download(@PathVariable String fileName, HttpServletResponse response){
        avatarService.download(fileName,response);
    }


}
